app.service('logService', function ($rootScope, $http) {
    var url = $rootScope.api.user;
    var data = {
        page: 1,
        limit: 10,
        items: [],
    };
    this.items = data.items;
    this.load = function (backmethod) {

        $http.get(url, { params: { page: data.page, limit: data.limit } }).success(function (res) {
            // console.log(res);
            angular.forEach(res.data, function(item){
                data.items.push(item);
            });
            data.page++;

            if( backmethod )
            {
                backmethod(res.data.length<data.limit );
            }
            // console.log(data.items);
        });
    };
    this.post = function (item) {
        $http.post(url, { data: item }).success(function (res) {
            console.log(res);
        });
    };
    this.get = function (id) {
        $http.get(url + '/' + id).success(function (res) {
            console.log(res);
        });
    };
    this.put = function (item) {
        $http.put(url + '/' + id, { data: item }).success(function (res) {
            console.log(res);
        });
    };
    this.delete = function (id) {
        $http.delete(url + '/' + id).success(function (res) {
            console.log(res);
        });
    }
});
